package com.hdp.jetpack_mvvm.lifecycle

import android.content.Context
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent


/**
 * 生命周期观察者
 */
open class LifecycleObserver1(context: Context, val callBack: (String) -> Unit) :
    LifecycleObserverBase(context) {

    val tag = "Lifecycle1"

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    fun subResume(owner: LifecycleOwner) {
        callBack.invoke("subResume,owner:" + owner.javaClass.canonicalName)
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    fun subResume2() {
        callBack.invoke("subResume2")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    override fun myOnCreate() {
        callBack.invoke("subCreate")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_ANY)
    fun subAny(owner: LifecycleOwner, event: Lifecycle.Event) {
        callBack.invoke("subAny_" + event.name)
    }

    fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
        callBack.invoke("onStateChanged")
    }
}